﻿using System.Security;
using MongoDB.Driver;

namespace AspNet.Identity.MongoDB
{
    public class MongoDbIdentityInstance
    {
        public MongoClient Client;
        public MongoDbIdentityInstance(string hostname, int port, string user, string password, string dataBaseName)
        {


            char[] pChar = password.ToCharArray();

            SecureString securepassword = new SecureString();

            foreach (char c in pChar)

            {

                securepassword.AppendChar(c);

            }
            var mongoClientSettings = new MongoClientSettings
            {
                Credential = MongoCredential.CreateCredential(dataBaseName, user, securepassword),
                Server = new MongoServerAddress(hostname, port)
            };
            Client = new MongoClient(mongoClientSettings);

        }
    }

    public static class MongoDbIdentityInstanceStore
    {
        public static MongoDbIdentityInstance IdentityConnection;
    }
}